﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace QstkCore.Util
{
    public static class StockPricesUtil
    {
        /// <summary>
        /// Computes stepwise (usually daily) returns relative to 0, where 0 implies no change in value.
        /// @return the array is revised in place
        /// </summary>
        public static IList<float> Returnize(this IList<float> prices)
        {
            Func<float, float, float> _returnize = (a,b) => (float) ((b/a)-1.0);
            IList<float> dailyReturns = prices.AsParallel().Select((x, index) => (index==0) ? 0 : _returnize(prices[index - 1], prices[index])).ToList();
            return dailyReturns;
        }
    }
}
